home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11669 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: abacus.abasoft.co.uk!not-for-mail
  2. From: dmb@abacus.abasoft.co.uk (David Byrne)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: Calling System Command in SUN C
  5. Date: 14 Mar 1996 11:05:33 -0000
  6. Organization: Abacus Software Ltd.
  7. Message-ID: <4i8uht$1po@abacus.abasoft.co.uk>
  8. References: <4i1hlu$asm@ni1.ni.net> <4i41j0$8nu@dawn.mmm.com>
  9. NNTP-Posting-Host: abacus.abasoft.co.uk
  10. X-NNTP-Posting-Host: abacus.demon.co.uk
  11.  
  12. In article <4i41j0$8nu@dawn.mmm.com>, Kevin J Hopps <kjhopps@mmm.com> wrote:
  13. >Ed Thomson (ethomson@cinahl.com) wrote:
  14. >> I am new to SUN C and am using version 3.0.1.
  15. >> I would like to execute a system command such as mail or a shell
  16. >> script I have generated and was wondering if anyone knew of an easy
  17. >> way to do this within C.
  18. >
  19. >The system(3S) function does what you want.  You pass it a string
  20. >which is the command to execute.  It returns the exit status of
  21. >the command.
  22.  
  23. Close - the exit status you want is in the 8 high-order bits of the return
  24. value. On the Sun, you need to do something like
  25.  
  26. {
  27.     int status;
  28.  
  29.     errno = 0;
  30.     status = system(cmd);
  31.     if (status == 127)
  32.         return(-1);
  33.     return(status>>8);
  34. }
  35. -- 
  36. David Byrne, Abacus Software, London, UK              Tel: +44 (0)171 603 9877
  37. Email: dmb@abacus.demon.co.uk                         Fax: +44 (0)171 603 6844
  38. Here's a koan: If you have ice-cream I will give you some. If you have none,
  39.                I will take it away from you. (it's an ice-cream koan).
  40.